<%= form_with(model: [@user, @repository, doc],
  url: user_repository_doc_path(params[:user_id], params[:repository_id], params[:id]),
  local: true,
  remote: true,
  id: "doc-form") do |form| %>

  <% if @doc.errors.any? %>
  <details class="doc-validation-error details-reset details-overlay" open>
    <summary></summary>
    <details-dialog class="box box--overlay d-flex flex-column anim-fade-in fast">
      <div class="box-body overflow-auto">
        <button class="btn-cancel" type="button" aria-label="Close dialog" data-close-dialog>
          <%= icon_tag "cancel" %>
        </button>
        <div class="mx-5 my-2">
          <div class="mb-4 text-center text-red">
            <p style="font-size: 32px"><%= icon_tag("error") %></p>
            <div class="mb-1 text-red">
              <strong><%= t(".Doc publish failed, because there has count issues", count: @doc.errors.count) %></strong>
            </div>
          </div>
          <ul class="ml-3">
            <% @doc.errors.full_messages.each do |msg| %>
             <li><%= msg %></li>
            <% end %>
          </ul>
        </div>
      </div>
    </details-dialog>
    </details>
  <% end %>


  <div id="editor-form">
    <div class="editor-navbar">
      <div class="navbar-title">
        <%= logo_tag href: @repository.to_path do %><span class="blue">Blue</span>Doc<% end %>
        <%= repository_name_tag @repository %>
        <span class= "divider">/</span>
        <a href="<%= doc.to_path %>" class="doc-link"><%= doc.title || t(".New doc") %></a>
        <span class="editor-message"></span>
      </div>
      <div class="navbar-buttons">
        <button type="submit" class="btn btn-primary"><%= t(".Publish") %></button>
        <button type="button" data-url="<%= user_repository_doc_path(@user, @repository, @doc) %>" class="btn btn-save"><%= t(".Save Draft") %></button>
        <span class="btn-doc-info-box"></span>
      </div>
    </div>

    <%= form.hidden_field :title, value: @doc.draft_title %>
    <%= form.hidden_field :format, value: @doc.format %>
    <%= form.text_area :body, class: "bluedoc-editor", value: doc.draft_body_plain, data: {
       plantuml_service_host: Setting.plantuml_service_host,
       mathjax_service_host: Setting.mathjax_service_host,
       repository_url: @repository.to_path,
       slug: @doc.slug
      }, style: "display: none" %>
    <%= form.text_area :body_sml, value: doc.draft_body_sml_plain, style: "display: none" %>
  </div>
<% end %>
<div class="editor-container"></div>